# 循环播放背景图
# NASA 2021-10-4
import pygame
import sys


def bg():
    pygame.init()
    winx = 800
    winy = 199
    screen = pygame.display.set_mode((winx, winy))
    fclock = pygame.time.Clock()
    bg_img = pygame.image.load('..\\pictures\\bg.png')
    bg_rect_a = bg_img.get_rect()
    bg_rect_b = bg_img.get_rect()
    bg_rect_b.x = winx
    while True:
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
        bg_rect_a = bg_rect_a.move(10, 0)
        bg_rect_b = bg_rect_b.move(10, 0)
        if bg_rect_a.x>=winx:
            bg_rect_a.x = 0-winx
        if bg_rect_b.x >= winx:
            bg_rect_b.x = 0-winx
        screen.blit(bg_img, (bg_rect_a.x,bg_rect_a.y))
        screen.blit(bg_img, bg_rect_b)
        pygame.display.update()
        screen.fill((0, 0, 0))
        fclock.tick(15)


if __name__ == '__main__':
    bg()  # background
